﻿using ObjectModels = PatientManagement.Common.ObjectModels;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PatientManagement.Database;

namespace PatientManagement.Translators
{
    public static class Translators
    {
        public static ObjectModels.Drug ToObjectModel(this GetDrugByNameResult from)
        {
            if (from == null) { return null; }
            return new ObjectModels.Drug()
            {
                Id = from.Id,
                Name = from.Name,
                Effect = from.Effect,
                Amount = from.Amount ?? 0,
                Price = from.Price,
                Description = from.Description,
                AlertAmount = from.AlertAmount ?? 0
            };
        }

        public static List<ObjectModels.Drug> ToObjectModels(this List<GetDrugByNameResult> from)
        {
            if (from == null) { return null; }
            var result = new List<ObjectModels.Drug>();
            foreach (var item in from)
            {
                result.Add(item.ToObjectModel());
            }
            return result;
        }

        public static ObjectModels.Drug ToObjectModel(this GetDrugsResult from)
        {
            if (from == null) { return null; }
            return new ObjectModels.Drug()
            {
                Id = from.Id,
                Name = from.Name,
                Effect = from.Effect,
                Amount = from.Amount ?? 0,
                Price = from.Price,
                Description = from.Description,
                AlertAmount = from.AlertAmount ?? 0
            };
        }

        public static List<ObjectModels.Drug> ToObjectModels(this List<GetDrugsResult> from)
        {
            if (from == null) { return null; }
            var result = new List<ObjectModels.Drug>();
            foreach (var item in from)
            {
                result.Add(item.ToObjectModel());
            }
            return result;
        }

        public static ObjectModels.Drug ToObjectModel(this GetDrugByAlertAmountResult from)
        {
            if (from == null) { return null; }
            return new ObjectModels.Drug()
            {
                Id = from.Id,
                Name = from.Name,
                Effect = from.Effect,
                Amount = from.Amount ?? 0,
                Price = from.Price,
                Description = from.Description,
                AlertAmount = from.AlertAmount ?? 0
            };
        }

        public static List<ObjectModels.Drug> ToObjectModels(this List<GetDrugByAlertAmountResult> from)
        {
            if (from == null) { return null; }
            var result = new List<ObjectModels.Drug>();
            foreach (var item in from)
            {
                result.Add(item.ToObjectModel());
            }
            return result;
        }
    }
}
